﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CM_GetAttachmentByContactID]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CM_GetAttachmentByContactID];
GO
CREATE PROCEDURE [dbo].[sproc_CM_GetAttachmentByContactID]
@contactid int
AS
    IF(@contactid=0)
    BEGIN
        SELECT * FROM UDS_CM_Attachment WHERE Type="contact"
    END
    ELSE
        SELECT * FROM UDS_CM_Attachment WHERE Type="contact" AND PertainID=@contactid